package com.intramirror.wd.common.bean;


import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;


@NoArgsConstructor
@Getter
public class R<T extends  Serializable> implements Serializable {
    public boolean success = true;         // 是否成功
    private Integer code = 0;
    private String error;
    private String message = "操作成功";     // 提示信息
    protected T result;                       // 返回结果
    private long timestamp = System.currentTimeMillis();    // 时间戳

    public static  R ok(Serializable result){
        return new R(result);
    }
    public static R error(String message){
        return new R(-1,message);
    }

    public R(T result) {
        this.result = result;
    }
    public R(Integer code, String message){
        this.success = code == 0;
        this.code = code;
        this.message = message;
    }
    public R(ErrorCode code, String error) {
        this.success = false;
        this.code = code.getCode();
        this.message = code.getError();
        this.error = error;
    }
    public R(ErrorCode code, String error, T list) {
        this.success = false;
        this.code = code.getCode();
        this.message = code.getError();
        this.error = error;
        this.result = list;
    }

}
